//
//  SIRefreshView.swift
//  SinaImiate
//
//  Created by xiaoming on 16/7/8.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

import UIKit

class SIRefreshView: UIView {
    
    ///父视图高度,为了子类继承使用
    var parentViewHeight: CGFloat = 0
    
    ///刷新状态
    var refreshState: SIRefreshState = .Normal {
        didSet {
            
            switch refreshState {
            case .Normal:
                
                tipIcon?.isHidden = false
                indicator?.stopAnimating()
                
                tipLabel?.text = "继续使劲拉..."
                
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon?.transform = CGAffineTransform.identity
                })
            case .Pulling:
                tipLabel?.text = "放手就刷新..."
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) + 0.001)
                })
                
            case .WillRefresh:
                tipLabel?.text = "正在刷新中..."
                
                tipIcon?.isHidden = true
                
                indicator?.startAnimating()
                
            }
        }
        
    }

    ///指示器
    @IBOutlet weak var indicator: UIActivityIndicatorView?
    ///提示图标
    @IBOutlet weak var tipIcon: UIImageView?

    ///提示标签
    @IBOutlet weak var tipLabel: UILabel?
    
    class func refreshView() -> SIRefreshView {
        
        let nib = UINib(nibName: "SIMeiTuanRefreshView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil)[0] as! SIRefreshView
        
    }
    
}
